'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 联盟基本功能--接口集合
 * @author sundbcn@gmail.com (sun debing)
 */

var pomelo = require('pomelo');
var unionBackJoin = require('./unionBasic/unionBackJoin.js');
var unionJoin = require('./unionBasic/unionJoin.js');
var accept = require('./unionBasic/accept.js');
var create = require('./unionBasic/create.js');
var dismiss = require('./unionBasic/dismiss.js');
var refuse = require('./unionBasic/refuse.js');
var upgadPosition = require('./unionBasic/upgadPosition.js');
var downGrade = require('./unionBasic/downGrade.js');
var unionKick = require('./unionBasic/unionKick.js');
var changName = require('./unionBasic/changName.js');
var changUnionMsg = require('./unionBasic/changUnionMsg.js');
var changUnionNotice = require('./unionBasic/changUnionNotice.js');
var buyShop = require('./unionBasic/buyShop.js');

module.exports = function (app) {
    return new Handler(app);
};

var Handler = function (app) {
    this.app = app;
    this.globalChannelService = app.get('globalChannelService');
};

/**
 * 创建公会
 */
Handler.prototype.create = function (msg, session, next) {
    var self = this;
    var selfGlobal = self.globalChannelService;
    var selfApp = self.app;
    create(selfApp, selfGlobal, msg, session, next);
};

/**
 * 解散公会
 */
Handler.prototype.dismiss = function (msg, session, next) {
    var self = this;
    var selfGlobalDismiss = self.globalChannelService;
    var selfAppDismiss = self.app;
    dismiss(selfGlobalDismiss, selfAppDismiss, msg, session, next);
};

/**
 * 申请加入公会
 */
Handler.prototype.join = function (msg, session, next) {
    unionJoin(msg, session, next);
};

/**
 * 撤销加入公会
 */
Handler.prototype.backJoin = function (msg, session, next) {
    unionBackJoin(msg, session, next);
};

/**
 * 审核成员加入公会
 */
Handler.prototype.accept = function (msg, session, next) {
    var self = this;
    var selfGlobal = self.globalChannelService;
    var selfApp = self.app;
    accept(selfApp, selfGlobal, msg, session, next);
};

/**
 * 拒绝成员加入公会
 */
Handler.prototype.refuse = function (msg, session, next) {
    refuse(msg, session, next);
};

/**
 * 联盟升职
 */
Handler.prototype.upgadPosition = function (msg, session, next) {
    upgadPosition(msg, session, next);
};

/**
 * 联盟降职
 */
Handler.prototype.downGrade = function (msg, session, next) {
    downGrade(msg, session, next);
};

/**
 * 联盟踢人
 */
Handler.prototype.unionKick = function (msg, session, next) {
    var self = this;
    var selfGlobalKick = self.globalChannelService;
    var selfAppKick = self.app;
    unionKick(selfAppKick, selfGlobalKick, msg, session, next);
};

/**
 * 修改名字
 */
Handler.prototype.changName = function (msg, session, next) {
    changName(msg, session, next);
};

/**
 * 修改联盟信息
 */
Handler.prototype.changUnionMsg = function (msg, session, next) {
    changUnionMsg(msg, session, next);
};

/**
 * 修改联盟公告
 */
Handler.prototype.changUnionNotice = function (msg, session, next) {
    changUnionNotice(msg, session, next);
};

/**
 * 联盟商城购买
 */
Handler.prototype.buyShop = function (msg, session, next) {
    buyShop(msg, session, next);
};
